import Vue from 'vue'
import store from '@/store'
import moment from 'moment'
import zonedata from './2021e.json'
moment.tz.load(zonedata)

Vue.filter('UTCFormat', function (dataStr, pattern = 'MM/DD/YYYY HH:mm z') {
  if (dataStr) {
    return moment(dataStr).utc().format(pattern)
  } else {
    return dataStr
  }
})

Vue.filter('ClientFormat', function (dataStr, pattern = 'HH:mm') {
  if (dataStr) {
    let formatLable = store.state.user.timeFormat ? store.state.user.timeFormat : 'MM/DD/YYYY'
    return moment.tz(dataStr, store.state.user.timezoneId).format(formatLable + ' ' + pattern) + ' ' + moment.tz(dataStr, store.state.user.timezoneId).format('zz')// store.state.user.timezoneName
  } else {
    return dataStr
  }
})

Vue.filter('ChicagoFormat', function (dataStr) {
  if (dataStr) {
    return moment.tz(dataStr, 'America/Chicago').format('MM/DD/YYYY HH:mm') + ' ' + moment.tz('America/Chicago').format('zz')
  } else {
    return dataStr
  }
})

Vue.filter('ClientFormatTimer', function (dataStr, pattern = 'HH:mm:ss') {
  if (dataStr) {
    let formatLable = store.state.user.timeFormat ? store.state.user.timeFormat : 'MM/DD/YYYY'
    return moment.tz(dataStr, store.state.user.timezoneId).format(formatLable + ' ' + pattern) + ' ' + moment.tz(dataStr, store.state.user.timezoneId).format('zz')
  } else {
    return dataStr
  }
})

// Leon Ji need it.
// 2020-09-07,'America/LasVegas'
// moment.tz('America/LasVegas').format('Z') ='-07:00'
